home *** CD-ROM | disk | FTP | other *** search
/ Hardcore Gamer Resource Kit / Hardcore Gamer Resource Kit - Disc 3.iso / screensavers / saver25.zip / SOURCE.ZIP / Saver.cpp < prev    next >
C/C++ Source or Header  |  1997-07-25  |  3KB  |  118 lines

  1. // Saver.cpp : Defines the class behaviors for the application.
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include "Saver.h"
  6. #include "drawwnd.h"
  7. #include "Saverdlg.h"
  8. #include "saverwnd.h"
  9.  
  10. #ifdef _DEBUG
  11. #undef THIS_FILE
  12. static char BASED_CODE THIS_FILE[] = __FILE__;
  13. #endif
  14.  
  15. /////////////////////////////////////////////////////////////////////////////
  16. // CSaverApp
  17.  
  18. BEGIN_MESSAGE_MAP(CSaverApp, CWinApp)
  19.     //{{AFX_MSG_MAP(CSaverApp)
  20.         // NOTE - the ClassWizard will add and remove mapping macros here.
  21.         //    DO NOT EDIT what you see in these blocks of generated code!
  22.     //}}AFX_MSG
  23.     ON_COMMAND(ID_HELP, CWinApp::OnHelp)
  24. END_MESSAGE_MAP()
  25.  
  26. TCHAR szConfig[]=_T("Config");
  27. /////////////////////////////////////////////////////////////////////////////
  28. // CSaverApp construction
  29.  
  30. CSaverApp::CSaverApp()
  31. {
  32.     // TODO: add construction code here,
  33.     // Place all significant initialization in InitInstance
  34. }
  35.  
  36. /////////////////////////////////////////////////////////////////////////////
  37. // The one and only CSaverApp object
  38.  
  39. CSaverApp theApp;
  40.  
  41. BOOL MatchOption(LPTSTR lpsz, char lpszOption)  //
  42. {
  43.     if (lpsz[0] == _T('-') || lpsz[0] == _T('/'))
  44.         lpsz++;
  45.  
  46.     if (lpsz[0] == lpszOption) return TRUE;
  47.     if (lpsz[0]+32 == lpszOption) return TRUE;    // uppercase
  48.  
  49.     return FALSE;
  50. }
  51.  
  52. /////////////////////////////////////////////////////////////////////////////
  53. // CSaverApp initialization
  54.  
  55. BOOL CSaverApp::InitInstance()
  56. {
  57.     // Standard initialization
  58.     // If you are not using these features and wish to reduce the size
  59.     //  of your final executable, you should remove from the following
  60.     //  the specific initialization routines you do not need.
  61.  
  62.     Enable3dControls();
  63.     SetRegistryKey(_T("Complex\\ProbableWorlds"));
  64.     
  65.     if (__argc == 1 || MatchOption(__argv[1], 'c')) DoConfig();
  66.     else if (MatchOption(__argv[1], 'p'))
  67.     {
  68. /*
  69. // sorry no preview!!!
  70.         CWnd* pParent = CWnd::FromHandle((HWND)atol(__argv[2]));
  71.         ASSERT(pParent != NULL);
  72.         CDrawWnd* pWnd = new CDrawWnd();
  73.         CRect rect;
  74.         pParent->GetClientRect(&rect);
  75.         pWnd->Create(NULL, WS_VISIBLE|WS_CHILD, rect, pParent, NULL);
  76.         m_pMainWnd = pWnd;
  77.         return TRUE;
  78. */
  79.         return FALSE;
  80.     }
  81.  
  82.     else if (MatchOption(__argv[1], 's')) 
  83.     {
  84.         // run the saver
  85.         CSaverWnd* pWnd = new CSaverWnd;
  86.         pWnd->Create();
  87.         m_pMainWnd = pWnd;
  88.         return TRUE;
  89.     }
  90.  
  91.     return FALSE;
  92. }
  93.  
  94. void CSaverApp::DoConfig()
  95. {
  96.     CSaverDlg dlg;
  97.  
  98.     // build up basepath for module default name... usually c:\windows\trans.xm
  99.     char basepath[512];
  100.     GetModuleFileName(GetModuleHandle(NULL),basepath,511);
  101.     char *tmp = strrchr(basepath, '\\');
  102.     sprintf(tmp+1, "trans.xm");
  103.  
  104.     dlg.m_musicDisable = this->GetProfileInt(szConfig, _T("Mute"), 0);
  105.     dlg.m_nName  = this->GetProfileString(szConfig, _T("FileName"), basepath);
  106.  
  107. #ifdef NOMUSIC
  108.     dlg.m_musicDisable = TRUE;
  109. #endif
  110.  
  111.     m_pMainWnd = &dlg;
  112.     if (dlg.DoModal() == IDOK)
  113.     {
  114.         this->WriteProfileInt(szConfig, _T("Mute"), dlg.m_musicDisable);
  115.         this->WriteProfileString(szConfig, _T("FileName"), dlg.m_nName);
  116.     }
  117. }
  118.